package com.mak001.lite.multiSkill.subs;

import org.rsbuddy.tabs.Inventory;
import org.rsbuddy.widgets.Bank;

import extras.mak001.AnimWatcher;
import com.mak001.lite.multiSkill.Methods;
import extras.mak001.Time;
import com.mak001.lite.multiSkill.subScript;
import com.rsbuddy.event.events.MessageEvent;
import com.rsbuddy.script.methods.Objects;
import com.rsbuddy.script.methods.Players;
import com.rsbuddy.script.methods.Skills;
import com.rsbuddy.script.methods.Walking;
import com.rsbuddy.script.util.Filter;
import com.rsbuddy.script.wrappers.Area;
import com.rsbuddy.script.wrappers.GameObject;
import com.rsbuddy.script.wrappers.Tile;

public class PowerChopperLite extends subScript {

	int[] axe = { 1351, 1349, 1353, 1361, 1355, 1357, 6739 };// worst to best
	int[] trees;
	String name;
	Area bankArea;
	Area treeArea;

	boolean drop;
	boolean switchB;

	public void setSwitch(boolean b) {
		if (switchB != b)
			switchB = b;
	}

	public enum state {
		TREEWALK, BANKWALK, BANK, CHOP, DROP
	}

	public state getState() {
		if (!Inventory.isFull()) {
			if (treeArea.contains(Players.getLocal().getLocation())) {
				return state.CHOP;
			} else {
				return state.TREEWALK;
			}
		} else {
			if (drop == true) {
				return state.DROP;
			} else {
				if (bankArea.contains(Players.getLocal().getLocation())) {
					return state.BANK;
				} else {
					return state.BANKWALK;
				}
			}
		}
	}

	@Override
	public void execute() {
		if (bankArea == null) {
			bankArea = Methods.getNearestBank(treeArea.getCentralTile());
		}

		switch (getState()) {
		case CHOP:
			if (!Players.getLocal().isMoving() && AnimWatcher.isIdle())
				if (Tree() != null) {
					if (Tree().interact("")) {
						sleep(500);
					}
				}
			break;
		case BANKWALK:
			Walking.findPath(bankArea.getCentralTile()).traverse();
			break;
		case TREEWALK:
			setSwitch(false);
			Walking.findPath(treeArea.getCentralTile()).traverse();
			break;
		case BANK:
			setSwitch(true);
			if (Bank.isOpen()) {
				Bank.depositAllExcept(axe);
			} else {
				Bank.open();
			}
			break;
		case DROP:
			Inventory.dropAllExcept(axe);
			break;
		}

	}

	public Area getArea() {
		return new Area(new Tile(3148, 3443), new Tile(3165, 3463));
	}

	public GameObject Tree() {
		return Objects.getNearest(new Filter<GameObject>() {
			@Override
			public boolean accept(GameObject o) {
				if (o != null) {
					for (int i : trees) {
						if (i == o.getId()) {
							if (getArea().contains(o.getLocation())) {
								return true;
							}
						}
					}
				}
				return false;
			}
		});
	}

	@Override
	public int[] required() {
		int[] req = { Methods.getBest(axe, Skills.WOODCUTTING) };
		// int[] req = axe;
		return req;
	}

	public void setInf(int[] tree, Area treeA, String s, boolean b) {
		this.trees = tree;
		this.name = s;
		this.drop = b;
		this.treeArea = treeA;
	}

	@Override
	public boolean canSwitch() {
		return switchB;
	}

	@Override
	public String getStatus() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int skill() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void messageRecieved(MessageEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String[] paintString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Time getTime() {
		// TODO Auto-generated method stub
		return null;
	}

}
